/**
 * 
 */
package obiee.documenter.core;

import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import obiee.documenter.utils.XMLUtils;

/**
 * @author danielgalassi@gmail.com
 *
 */
public class OBIEEDocumenter {

	/**
	 * Loads stylesheets stored within the JAR file
	 * @param resource name of the stylesheet
	 * @return an InputStream reference of the stylesheet
	 */
	private InputStream getInternalResource(String resource) {
		InputStream bundledResource = null;
		try {
			bundledResource = getClass().getClassLoader().getResourceAsStream(resource);
		} catch (Exception e) {
			System.out.println("Stylesheet " + resource + " could not be loaded.");
		}
		return bundledResource;
	}

	/**
	 * @param args command line arguments
	 */
	public static void main(String[] args) {
		Map<String, String> params = new HashMap<String, String>();
		String xudml = "";
		boolean saInvoked = false;
		boolean fileInvoked = false;
		for (String arg : args) {
			if (arg.startsWith("-subjectarea=")) {
				params.put("MySubjectArea", arg.substring(13));
				saInvoked = true;
			}
			if (arg.startsWith("-xudml=")) {
				xudml = arg.substring(7);
				fileInvoked = true;
			}
		}
		if (!fileInvoked || !saInvoked) {
			System.out.println("Exiting, missing parameters...");
			System.out.println("-xudml=<file>");
			System.out.println("-subjectarea=<subject area> (use quotation marks)");
			return;
		}

		OBIEEDocumenter me = new OBIEEDocumenter();
		InputStream style1 = me.getInternalResource("obiee/documenter/stylesheets/DataCapture.xsl");
		//InputStream html = me.getInternalResource("stylesheets/Output.xsl");
		File temp1 = new File("temp1.xml");
		//File results = new File("BusMatrix.html");
		XMLUtils.applyStylesheet(xudml, style1, temp1, params);
		//XMLUtils.applyStylesheet(temp1, html, results, null);
		//temp1.deleteOnExit();
	}
}
/*
To generate subject area-based documentation:
-subjectarea="Procurement and Spend - Purchase Order Financials" -xudml=sampleCases/production.xml
 */
